<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/prettyphoto.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.prettyphoto.js"></script>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.autocomplete.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.autocomplete.js"></script>
<script type="text/javascript">
get_check = function(){
	var ids = '';
	$(".list_table").find("input[type='checkbox']").each(function(){
		if ($(this).is(":checked"))
		{
			if (ids)
			{
				ids += ',';
			}
			ids += $(this).val();
		}
	});
	return ids;
};
$(function(){
	$(".ajax_provider").autocomplete("<?=url('Finance::overseas/ProviderInfoAjax')?>").result(function(event, data, formatted){});
	$(".datepicker").datepicker({dateFormat:'yy-mm-dd',changeMonth:true});
	$("a[rel^='pretty_photo']").prettyPhoto({theme:'facebook'});
	$(".view").toggle(function(){
		$(this).parent().parent().next().show();
	},function(){
		$(this).parent().parent().next().hide();
	});
	$("#check_all").click(function(){
		if ($(this).is(":checked"))
		{
			$(".list_table input[type='checkbox']").attr("checked", true);
		}
		else
		{
			$(".list_table input[type='checkbox']").attr("checked", false);
		}
	});
	$("#audit_btn").click(function(){
		var ids = get_check();
		if (!confirm("确定审核？"))
		{
			return false;
		}
		if (! ids)
		{
			alert("请选择采购单");
			return false;
		}
		window.location.href = "<?=url('Finance::Overseas/FBAInstoreFinanceAudit')?>&ids=" + ids;
	});
});
</script>
<form method="get">
<?include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th>采购日期</th>
	<td>
		<input type="text" name="begin_purchase_time" class="datepicker" value="<?=isset($_GET['begin_purchase_time'])?$_GET['begin_purchase_time']:''?>" /> to
		<input type="text" name="end_purchase_time" class="datepicker" value="<?=isset($_GET['end_purchase_time'])?$_GET['end_purchase_time']:''?>" />
	</td>
</tr>
<tr>
	<th>到仓时间</th>
	<td>
		<input type="text" name="begin_arrived_time" class="datepicker" value="<?=isset($_GET['begin_arrived_time']) ? $_GET['begin_arrived_time'] : ''?>" /> to
		<input type="text" name="end_arrived_time" class="datepicker" value="<?=isset($_GET['end_arrived_time']) ? $_GET['end_arrived_time'] : ''?>" />
	</td>
</tr>
<tr>
	<th>仓库审核日期</th>
	<td>
		<input type="text" name="begin_storage_audit_time" class="datepicker" value="<?=isset($_GET['begin_storage_audit_time'])?$_GET['begin_storage_audit_time']:''?>" /> to
		<input type="text" name="end_storage_audit_time" class="datepicker" value="<?=isset($_GET['end_storage_audit_time'])?$_GET['end_storage_audit_time']:''?>" />
	</td>
</tr>
<tr>
	<th>财务审核日期</th>
	<td>
		<input type="text" name="begin_finance_audit_time" class="datepicker" value="<?=isset($_GET['begin_finance_audit_time'])?$_GET['begin_finance_audit_time']:''?>" /> to
		<input type="text" name="end_finance_audit_time" class="datepicker" value="<?=isset($_GET['end_finance_audit_time'])?$_GET['end_finance_audit_time']:''?>" />
	</td>
</tr>
<tr>
	<th>采购人员</th>
	<td>
		<select name="purchase_user_id">
			<option value="">请选择..</option>
			<?foreach ($user as $u):?>
			<option value="<?=$u['id']?>" <?if (isset($_GET['purchase_user_id'])&&$_GET['purchase_user_id']==$u['id'])echo "selected='selected'"?>><?=$u['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>供应商</th>
	<td>
		<input type="text" class="ajax_provider" name="ajax_provider" value="<?=isset($_GET['ajax_provider']) ? $_GET['ajax_provider'] : ''?>"/>
	</td>
</tr>
<tr>
	<th>结款类型</th>
	<td>
		<select name="payment_type">
			<option value="">请选择..</option>
			<? foreach (Q::ini('custom_flag/purchase_order_payment_type') as $pt):?>
			<option value="<?=$pt['value']?>" <?if (isset($_GET['payment_type']) && $_GET['payment_type'] == $pt['value'])echo "selected='selected'" ?>><?=$pt['name']?></option>
			<? endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>ID</th>
	<td><input type="text" name="id" value="<?=isset($_GET['id']) ? $_GET['id'] : ''?>" /></td>
</tr>
<tr>
	<th>产品编号</th>
	<td><input type="text" name="product_basic_number" value="<?=isset($_GET['product_basic_number']) ? $_GET['product_basic_number'] : ''?>" /> 输入产品编号后六位例如：000001</td>
</tr>
<tr>
	<th>仓库</th>
	<td>
		<select name="warehouse_id">
			<option value="">请选择</option>
			<?foreach ($warehouse as $w):?>
			<option value="<?=$w['id']?>" <?if (isset($_GET['warehouse_id']) && $_GET['warehouse_id'] == $w['id']) echo "selected='selected'"?>><?=$w['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>状态</th>
	<td>
		<?foreach (Q::ini('custom_flag/fba_overseas_instore_status') as $w):?>
		<label><input type="checkbox" name="status[<?=$w['value']?>]" value="<?=$w['value']?>" <?if (isset($_GET['status']) &&  array_key_exists($w['value'], $_GET['status'])) echo "checked='checked'"?> /> <?=$w['name']?></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<th>仓库审核</th>
	<td>
		<?foreach (Q::ini('custom_flag/overseas_instore_storage_audit') as $sa):?>
		<label><input type="checkbox" name="storage_audit[<?=$sa['value']?>]" value="<?=$sa['value']?>" <?=isset($_GET['storage_audit']) && in_array($sa['value'], $_GET['storage_audit']) ? 'checked="checked"' : ''?> /><?=$sa['name']?></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<th>财务审核</th>
	<td>
		<?foreach (Q::ini('custom_flag/overseas_instore_finance_audit') as $fa):?>
		<label><input type="checkbox" name="finance_audit[<?=$fa['value']?>]" value="<?=$fa['value']?>" <?=isset($_GET['finance_audit']) && in_array($fa['value'], $_GET['finance_audit']) ? 'checked="checked"' : ''?> /><?=$fa['name']?></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<th></th>
	<td><input type="submit" class="button" value="查询" /></td>
</tr>
</table>
</form>
<table class="list_table" width="100%" id="list">	
<tr>
	<th width="20"></th>
	<th>ID</th>
	<th>仓库</th>
	<th>采购时间</th>
	<th>到仓时间</th>
	<th>仓库审核时间</th>
	<th>财务审核时间</th>
	<th>采购人员</th>
	<th>总金额</th>
	<th>结款类型</th>
	<th>状态</th>
	<th>备注</th>
	<th width="120">操作</th>
</tr>
<?foreach ($instore as $i):?>
<tr>
	<td><input type="checkbox" value="<?=$i['id']?>" /></td>
	<td><?=$i['id']?></td>
	<td><?=$i['warehouse_name']?></td>
	<td title="采购人员：<?=$i['purchase_user_name']?>"><?=substr($i['purchase_time'], 0, 10)?></td>
	<td title="到仓人员：<?=$i['arrived_user_name']?>"><?=substr($i['arrived_time'], 0, 10)?></td>
	<td title="仓库审核人员：<?=$i['storage_audit_user_name']?>"><?=substr($i['storage_audit_time'], 0, 10)?></td>
	<td title="财务审核人员：<?=$i['finance_audit_user_name']?>"><?=substr($i['finance_audit_time'], 0, 10)?></td>
	<td><?=$i['purchase_user_name']?></td>
	<td><?=sprintf('%.2f', $i['total_price'])?></td>
	<td><?=Helper_BSS_Normal::getIniOne('purchase_order_payment_type', 'value', $i['payment_type'], 'name')?></td>
	<td><?=Helper_BSS_Normal::getIniOne('winit_overseas_instore_status', 'value', $i['status'], 'name')?></td>
	<td><?=$i['notes']?></td>
	<td>
		<a class="view" href="javascript:void(0);">查看</a>
		<input type="hidden" name="id" value="<?=$i['id']?>" />
		<?if ($i['finance_audit'] != Q::ini('custom_flag/overseas_instore_finance_audit/audited/value') && ($i['status'] == Q::ini('custom_flag/fba_overseas_instore_status/confirmed_send/value') || $i['status'] == Q::ini('custom_flag/fba_overseas_instore_status/arrived/value'))):?>
		<a href="<?=url('Finance::Overseas/FBAInstoreFinanceAudit', array('ids' => $i['id']))?>">审核</a>
		<?else:?>
		<font color="#aaaaaa">审核</font>
		<?endif;?>
	</td>
</tr>
<tr class="detail" style="display: none;">
	<td colspan="14">
		<div align="left"><strong>入库产品信息</strong></div>
		<table width="100%" class="list_table">
			<tr>
				<th>产品编号</th>
				<th>产品名称</th>
				<th>供应商</th>
				<th>数量</th>
				<th>价格</th>
			</tr>
			<?$total_price = $total_qty = 0;?>
			<?foreach ($i['item'] as $ii):?>
			<?php
				$total_price += $ii['price'] * $ii['quantity'];
				$total_qty += $ii['quantity'];
			?>
			<tr>
				<td>
					<?=$ii['number']?>
					<?if ($ii['pic_url']):?>
						<?$pretty_photo_number = 0;?>
						<?foreach ($ii['pic_url'] as $ip):?>
						<a rel="pretty_photo[<?=$ii['id']?>]" href="<?=$ip?>"><?if(!$pretty_photo_number):?><span class="img_icon"></span><?endif;?></a>
						<?$pretty_photo_number = 1;?>
						<?endforeach;?>
					<?endif;?>
				</td>
				<td><?=$ii['product_basic_name']?></td>
				<td><?=$ii['provider_name']?></td>
				<td><?=$ii['quantity']?></td>
				<td><?=$ii['price']?></td>
			</tr>
			<?endforeach;?>
			<tr>
				<td colspan="3" align="right"><b>总计：</b></td>
				<td><b><?=$total_qty?></b></td>
				<td><b><?=sprintf('%.2f', $total_price)?></b></td>
			</tr>
		</table>
	</td>
</tr>
<?endforeach;?>
</table>
<?=$page;?>
<table>
<tr>
	<td><label><input type="checkbox" id="check_all" /> 全选</label> | </td>
	<td align="left"><input type="button" value="批量审核" class="button" id="audit_btn" /></td>
</tr>
</table>
搜索条件的总金额：RMB <strong><?=number_format($amount, 2)?></strong>
<?php $this->_endblock();?>